package sports

import (
	"github.com/robfig/cron/v3"
	"longmen/server/config/global"
	"longmen/server/internal/services/nami/api"
	"longmen/server/internal/services/nami/api/v5/sports/basketball"
	"longmen/server/internal/services/nami/api/v5/sports/cricket"
	"longmen/server/internal/services/nami/api/v5/sports/football"
	"longmen/server/internal/services/nami/config"
	"longmen/server/internal/services/nami/services"
)

var taskMap = []api.GetTask{
	football.GetTaskMap,
	basketball.GetTaskMap,
	cricket.GetTaskMap,
}
var allTask []config.Task

func SetUpTask(cron *cron.Cron) {
	for i := 0; i < len(taskMap); i++ {
		allTask = append(allTask, taskMap[i]()...)
	}
	for i := 0; i < len(allTask); i++ {
		taskId, err := cron.AddFunc(allTask[i].Spec, allTask[i].Fun)
		if err != nil {
			global.Log.Fatalf("add func error: %v", err)
		}
		allTask[i].CronId = taskId
	}
	cron.AddFunc("@every 10s", services.NewAutoCreateMatchRoom().SyncRoom)
	// 常驻任务
}
